package cn.kduck.module.menu.query;

import cn.kduck.core.dao.definition.BeanDefDepository;
import cn.kduck.core.dao.definition.BeanEntityDef;
import cn.kduck.core.dao.query.QueryCreator;
import cn.kduck.core.dao.query.QuerySupport;
import cn.kduck.core.dao.sqlbuilder.ConditionBuilder.ConditionType;
import cn.kduck.core.dao.sqlbuilder.SelectBuilder;
import cn.kduck.core.service.ParamMap;
import cn.kduck.module.menu.service.Menu;
import cn.kduck.module.menu.service.MenuService;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class PublicMenuQuery implements QueryCreator {
    @Override
    public QuerySupport createQuery(Map<String, Object> paramMap, BeanDefDepository depository) {
        paramMap = ParamMap.create().set("isPublic", Menu.IS_PUBLIC_YES).set("menuType",Menu.MENU_TYPE_MENU_ITEM).toMap();
        BeanEntityDef menuDef = depository.getEntityDef(MenuService.CODE_MENU);
        SelectBuilder sqlBuilder = new SelectBuilder(menuDef,paramMap);
        sqlBuilder.where().and("IS_PUBLIC", ConditionType.EQUALS,"isPublic").and("MENU_TYPE", ConditionType.EQUALS,"menuType");
        return sqlBuilder.build();
    }
}
